package myky.com.doctorapp.utils;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import myky.com.doctorapp.wight.GridLayoutItemDecoration;
import myky.com.doctorapp.wight.MyLayoutManager;
import myky.com.doctorapp.wight.RecycleViewDivider;

/**
 * Created by 61904 on 2017/4/18.
 * recycler配置类
 */

public class RecyclerUtils {


    private static int from,to;
    private static String sortBy;


    //配置Recyler参数（竖向）
    public static void setRecylerParms(Context context, RecyclerView recyclerView){


        LinearLayoutManager layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setNestedScrollingEnabled(false);//解决scrollview和recycler滑动冲突
        layoutManager.setOrientation(OrientationHelper.VERTICAL);
        recyclerView.addItemDecoration(new DividerItemDecoration(context,1));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);

    }

    //配置Recyler参数（竖向）
    public static void setRecyclerParms(Context context, RecyclerView recyclerView, int line){


        LinearLayoutManager layoutManager=new LinearLayoutManager(context);
        layoutManager.setOrientation(OrientationHelper.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setNestedScrollingEnabled(false);//解决scrollview和recycler滑动冲突


        recyclerView.addItemDecoration(new DividerItemDecoration(context,line));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);

    }
    //配置Recyler参数（竖向）
    public static void setRecyclerDivider(Context context, RecyclerView recyclerView, int line){

        LinearLayoutManager layoutManager=new LinearLayoutManager(context);
        if (layoutManager != null){
            recyclerView.setLayoutManager(layoutManager);
        }
        recyclerView.setNestedScrollingEnabled(false);//解决scrollview和recycler滑动冲突
        layoutManager.setOrientation(OrientationHelper.VERTICAL);
        recyclerView.addItemDecoration(new RecycleViewDivider(context,OrientationHelper.VERTICAL,line, Color.BLUE));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    }

    //配置Recyler参数(横向,自动换行)
    public static void setRecyclerHorizontal(Context context, RecyclerView recyclerView){
    //设置recyclerView横向布局
        MyLayoutManager myLayoutManager=new MyLayoutManager();
        myLayoutManager.setAutoMeasureEnabled(true);
        recyclerView.setLayoutManager(myLayoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);

    }
    //配置Recyler参数(横向滑动）
    public static void setRecyclerHorizontalScroll(Context context, RecyclerView recyclerView){
        //设置recyclerView横向布局
        LinearLayoutManager layoutManager=new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);

    }

    //配置Recyler参数(横向,病历图片3列)
    public static void setRecyclerHorizontal(Context context, RecyclerView recyclerView, int num){
        recyclerView.setNestedScrollingEnabled(false);
        GridLayoutManager layoutManager=new GridLayoutManager(context,num);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);

    }

    //配置Recyler参数(横向,病历图片3列)
    public static void setRecyclerGridLayout(Context context, RecyclerView recyclerView, int num){
        recyclerView.setNestedScrollingEnabled(false);
        GridLayoutManager layoutManager=new GridLayoutManager(context,num);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setNestedScrollingEnabled(false);
        GridLayoutItemDecoration itemDecoration = new GridLayoutItemDecoration(num);
        itemDecoration.setDivideParams(10, 10);
        recyclerView.addItemDecoration(itemDecoration);
        recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);

    }

    //获取加载更多分页加载字段
    public static String getSortByFrist(int froms, int tos){

        from=froms;
        to=tos;
        sortBy=froms+"-"+tos;
        return sortBy;
    }


    //获取加载更多分页加载字段
    public static String getSortByItem(int counts){


        from=to;
        to+=counts;
        sortBy=from+"-"+to;
        return sortBy;
    }
}
